package cn.iocoder.yudao.module.promotion.groupon.pojo.vo;

import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.business.basic.pojo.dto.SaveDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.PositiveOrZero;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 *  这里是文件说明
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2025/03/28
 */
@Data
@Valid
public class GrouponProductSaveDTO extends SaveDTO {

    @Schema(description = "团购套编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    @NotNull(message = "团购套编号不能为空")
    private Long packageId;

    @Schema(description = "产品 SKU 编号，选择现有产品时关联", example = "1")
    private Long skuId;

    @Schema(description = "产品 SKU 名称", example = "小米 Pro 16")
    private String name;

    @Schema(description = "产品 SKU 封面", example = "https://example.local/xx.png")
    private String picUrl;

    @Schema(description = "成本价，单位为分，0表示免费", example = "100")
    @PositiveOrZero
    private Integer costPrice;

    @Schema(description = "单卖销售价，单位为分，0表示免费", example = "100")
    @PositiveOrZero
    private Integer originPrice;

    @Schema(description = "套卖销售价，单位为分，0表示免费", example = "100")
    @PositiveOrZero
    private Integer price;

    @Schema(description = "套卖会员价，单位为分，0表示免费", example = "100")
    @PositiveOrZero
    private Integer vipPrice;

    @Schema(description = "数量", defaultValue = "1", example = "1")
    @Min(value = 1, message = "数量必须大于 0")
    private Integer count;

    @Schema(description = "单位，如：次、条、瓶、份", example = "次")
    @Length(max = 10, message = "单位不能超过 10 个字符")
    private String unit;

    @SuppressWarnings("unused")
    @AssertTrue(message = "产品 SKU 编号及产品信息不能同时为空")
    public boolean validSkuIdAndSkuInfo() {
        if (skuId != null && skuId > 0) {
            return true;
        }
        return StrUtil.isNotBlank(name) && price != null && count != null;
    }

}
